from sqlalchemy import select
from database.engine import get_session_factory
from database.models.purpose import Purpose


class SynOrmPurposeQueries:
    @staticmethod
    def get_purposes_names():
        with get_session_factory()() as session:
            query = (
                select(Purpose.name)
            )
            result_iterator = session.execute(query)
            result = result_iterator.scalars().all()
            return result
        
        
    @staticmethod
    def insert_purposes():
        with get_session_factory()() as session:
            purposes = [
                Purpose(name="Похудеть", coef=0.85),
                Purpose(name="Держать вес", coef=1.0),
                Purpose(name="Набрать вес", coef=1.15),
            ]
            for purpose in purposes:
                if not session.get(Purpose, {"name": purpose.name}):
                    session.add(purpose)
            session.commit()
            